from xml.dom.minidom import Element

from selenium.webdriver.support.wait import WebDriverWait


class KeyWord(object):
    """
    Base class which will be inherited by all Page Objects
    """

    def __init__(self, driver):
        self.driver = driver

    def wait_find_element(self, position_express: str, xpath_expression: str):
        """
        定位单个元素
        :param xpath_expression:
        :return:
        """
        return WebDriverWait(self.driver, 10, 0.5).until(
            lambda d: self.driver.find_element(position_express, xpath_expression)
        )

    def wait_find_elements(self, position_express: str, xpath_expression: str):
        """
        定位单个元素
        :param xpath_expression:
        :return:
        """

        return WebDriverWait(self.driver, 20, 0.5).until(
            lambda d: self.driver.find_elements(position_express, xpath_expression)
        )

    def goto_url(self, url):
        self.driver.get(url)

    def msg(self, position_express: str, xpath_expression: str):
        msg = WebDriverWait(self.driver, 20, 0.5).until(
            lambda d: self.driver.find_element(position_express, xpath_expression).text
        )
        return msg
    def click(self,position_express:str,xpath_express: str):
        ele=self.wait_find_element(position_express,xpath_express)
        ele.click()
    def ele_click(self,ele):
        ele.click()
    def send_keys(self,position_express:str,xpath_express: str,text:str):
        ele = self.wait_find_element(position_express, xpath_express)
        ele.send_keys(text)
    def assert_text(self,msg,text):
        assert msg == text